//
//  BottomTabs.swift
//  Music
//
//  Created by liaokylin on 2024/10/4.
//

import SwiftUI

enum Tab: CaseIterable{
    case homepage
    case course
    case create
    case collect
    case mine
    
    var text:String{
        switch self {
        case .homepage:
            return "首页"
        case .course:
            return "课堂"
        case .create:
            return ""
        case .collect:
            return "收藏"
        case .mine:
            return "我"
        }
    }
    
    var icon:String {
        switch self{
        case .homepage:
            return "house"
        case .course:
            return "video"
        case .create:
            return "plus.app"
        case .collect:
            return "star"
        case .mine:
            return "person"
        }
    }
    
    var iconSelected:String {
        switch self{
        case .homepage:
            return "house.fill"
        case .course:
            return "video.fill"
        case .create:
            return "plus.app.fill"
        case .collect:
            return "star.fill"
        case .mine:
            return "person.fill"
        }
    }
}


struct BottomTabs: View {
    @Binding var currentSelected:Tab
    @Binding  var isPresented:Bool
    var body: some View {
        HStack(alignment: .bottom){
            ForEach(Tab.allCases,id: \.self) { tabItem in
                Button{
                    currentSelected = tabItem
                } label:{
                    VStack{
                        if !tabItem.text.isEmpty {
                            Image(systemName: currentSelected == tabItem ? tabItem.iconSelected :tabItem.icon)
                                .font(.system(size: 24))
                              //  .frame(height: 30)
                            Text(tabItem.text)
                                .font(.caption)
                                .font(.body.bold())
                        }else {
                            Image("plus")
                                .fullScreenCover(isPresented: $isPresented, content: {
                                    CreateWorks()
                                })
                                .font(.system(size: 36))
                                .onTapGesture {
                                    isPresented.toggle()
                                }
                        }
                    }
                    .foregroundColor(currentSelected == tabItem ? Color(hex: "#444444") : .secondary)
                    .frame(maxWidth: .infinity,alignment: .bottom)
                    .padding(.vertical,10)
                }
            }
        }
    }
}

#Preview {
    
    BottomTabs(currentSelected: .constant(Tab.collect),isPresented: .constant(false))
}
